#include<stdio.h>
#include<stdlib.h>
using namespace std;
typedef struct node{
    struct node *next;
    int data;
}*list;
list create(list head){
    if(head==NULL){
        head=(list)malloc(sizeof(struct node));
        head->next=NULL;
    }
    int x;
    scanf("%d",&x);
    while(x!=-1){
        list node=(list)malloc(sizeof(struct node));
        node->data=x;
        node->next=head->next;
        head->next=node;//头插法
        scanf("%d",&x);
    }
    return head;
}
void fun(list head,int k){
    if(head==NULL)
        return;
    list p=head->next,pre=head->next;
    int count=0;
    while(p&&count<k){
        p=p->next;
        count++;
    }
    if(p==NULL){
        printf("倒数第%d个元素是%d",k,pre->data);
        return;
    }
    while(p){
        p=p->next;
        pre=pre->next;
    }
    printf("倒数第%d个元素是%d",k,pre->data);
}
int main(){
    list head=NULL;
    head=create(head);
    fun(head,3);
    return 0;
}